package com.csr.csrcheck.controller;

import com.csr.csrcheck.pojo.Product;
import com.csr.csrcheck.service.ProductService;
import com.csr.csrcheck.service.ex.ProductException;
import com.csr.csrcheck.util.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RequestMapping({"product"})
@RestController
public class EquipmentController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.EquipmentController.class);

    @Resource
    private ProductService productService;

    @GetMapping({"productlist"})
    public JsonResult<List<Product>> Companylist(HttpServletResponse response) throws IOException, ServletException {
        List<Product> list = this.productService.getProductlist();
        if (list == null)
            throw new ProductException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @GetMapping({"productlist2"})
    public JsonResult<List<Product>> CompanyList2(@RequestParam("name") String product_name) {
        List<Product> list2 = this.productService.getProductlistbyname(product_name);
        if (list2 == null)
            throw new ProductException("");
        return new JsonResult(Integer.valueOf(0), "json", list2);
    }
}
